import { defineStore } from 'pinia';
export const Store = defineStore('store', {
    state: () => ({
        CurUser: {},//用户信息
        menuList: [],//菜单列表
        hasRoutes: false,//是否已经生成路由
        permList: [], // 权限列表

        editableTabsValue: "Home", // 可编辑标签页的值，默认为系统首页
        editableTabs: [
            {
                title: "系统首页",
                name: "Home",
            },
        ], // 可编辑标签页的数组，初始只包含系统首页
    }),
    actions: {
          
        setMenuList(data) {

            this.menuList = data;
            localStorage.setItem("menu",JSON.stringify(data) );
        },
        setUser( data) {

            this.CurUser = data;
            localStorage.setItem("CurUser", JSON.stringify(data) );
        },
        setPermList( data) {

            this.permList = data;
            localStorage.setItem("perm", JSON.stringify(data) );
        },
        changeRoutethiss( hasRoutes) {
            this.hasRoutes = hasRoutes;
        },
        resetStatus() {
            this.menuList = [];
            this.CurUser = {};
            this.permList = [];
            this.hasRoutes = false;
            this.editableTabsValue = "Home", // 可编辑标签页的值，默认为系统首页
                this.editableTabs = [
                    {
                        title: "系统首页",
                        name: "Home",
                    },
                ]
            localStorage.removeItem("CurUser");
            localStorage.removeItem("perm");
            localStorage.removeItem("menu");
        },
        addTab(tab) {
            console.log(tab);
            // 添加标签页
            let index = this.editableTabs.findIndex((e) => e.name === tab.path);
            if (index === -1) {
                // 若该标签页不存在，则添加
                this.editableTabs.push({
                    title: tab.name,
                    name: tab.path,
                });
            }
            this.editableTabsValue = tab.path; // 将当前选中的标签页值更新为添加的标签页
            
        },
        
    },
  
});